//
//  OrginformationController.m
//  Weiweiyunshi
//
//  Created by 张旭峰 on 2017/1/24.
//  Copyright © 2017年 王译. All rights reserved.
//

#import "OrginformationController.h"
#import "OrgListInformationView.h"
#import <MessageUI/MessageUI.h>
#import "TestViewController.h"
@interface OrginformationController ()<UITableViewDataSource,UITableViewDelegate,MFMailComposeViewControllerDelegate>

@end

@implementation OrginformationController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title=@"详细信息";
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"header_back_icon"] style:UIBarButtonItemStyleDone target:self action:@selector(pop)];
    self.navigationItem.leftBarButtonItem = backItem;
    
    OrgListInformationView *view = [[OrgListInformationView alloc]init];
    
    [view.portraitImageView sd_setImageWithURL:[NSURL URLWithString:self.img]];
    view.nameLabel.text = self.userName;
    view.orgLabel.text = self.deptName;
    
    view.informationListView.dataSource = self;
    view.informationListView.delegate = self;
    view.informationListView.scrollEnabled = NO;
    view.informationListView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    self.view = view;
    
     [view.enterButton addTarget:self action:@selector(enterRoom:) forControlEvents:UIControlEventTouchUpInside];
    // Do any additional setup after loading the view.
}
-(void)pop
{
     [self.navigationController popViewControllerAnimated:YES];
}
-(void)enterRoom:(id)sender{
    
    
    TestViewController *test = [[TestViewController alloc]init];
    test.guestVRoomKey = self.vidyoKey;
    NSLog(@"%@",self.vidyoKey);
    [test showVidyo];
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 4;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
    }
    
    //个人信息tableView赋值
    switch (indexPath.row) {
        case 0:
            cell.textLabel.text = @"姓名";
            cell.detailTextLabel.text = self.userName;
            break;
        case 1:
            cell.textLabel.text = @"电话";
           
            cell.detailTextLabel.text = self.mobile;
            break;
            
        case 2:
            cell.textLabel.text = @"邮箱";
            cell.detailTextLabel.text = self.email;
            break;
        case 3:
            cell.textLabel.text = @"部门";
            cell.detailTextLabel.text = self.pdeptName;
            break;
        default:
            break;
    }
    
    return cell;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row ==1) {
        NSString *str = [NSString stringWithFormat:@"telprompt:%@",self.mobile];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    }
    else if (indexPath.row ==2){
        [self sendEmailAction];
    }
}


#pragma mark - 发邮件 -

-(void)sendEmailAction{
    MFMailComposeViewController *mailCompose = [[MFMailComposeViewController alloc]init];
    mailCompose.mailComposeDelegate = self;
    [mailCompose setSubject:@"我是邮件主题"];
    [mailCompose setToRecipients:@[self.email]];
    
    NSString *emailContent = @"我是邮件内容";
    [mailCompose setMessageBody:emailContent isHTML:NO];
    [self presentViewController:mailCompose animated:YES completion:nil];
    
}


- (void)mailComposeController:(MFMailComposeViewController *)controller
          didFinishWithResult:(MFMailComposeResult)result
                        error:(NSError *)error
{
    switch (result)
    {
        case MFMailComposeResultCancelled: // 用户取消编辑
            // 关闭邮件发送视图

            NSLog(@"------》》》Mail send canceled...");
//            [self dismissViewControllerAnimated:YES completion:nil];
        case MFMailComposeResultSaved: // 用户保存邮件
            NSLog(@"Mail saved...");
            break;
        case MFMailComposeResultSent: // 用户点击发送
            NSLog(@"Mail sent...");
            break;
        case MFMailComposeResultFailed: // 用户尝试保存或发送邮件失败
            NSLog(@"Mail send errored: %@...", [error localizedDescription]);
            break;
    }
    
    // 关闭邮件发送视图
    [self dismissModalViewControllerAnimated:YES];
//    [controller presentViewController:self animated:YES completion:nil];
    [self.navigationController popViewControllerAnimated:YES];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
